<?php
declare(strict_types=1);

use support\command\phinx\MigrationBaseClass;

final class CreateAttachmentsTable extends MigrationBaseClass
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $this->schema->create('attachments', function (Illuminate\Database\Schema\Blueprint $table) {
            $table->increments('id');
            $table->integer('admin_id')->default(0)->comment('管理员');
            $table->integer('user_id')->default(0)->comment('用户');
            $table->string('url', 255)->comment('路径');
            $table->string('filename', 100)->comment('文件名');
            $table->integer('filesize')->comment('文件大小');
            $table->string('mimetype', 100)->nullable(true)->comment('类型');
            $table->string('storage', 100)->default('local')->comment('位置');
            $table->string('sha1', 40)->nullable(true)->comment('文件 sha1编码');
            $table->timestamps();
            $table->unique(['sha1']);
        });
    }
}
